package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单相关接口
 */
@Slf4j
@RequestMapping("/admin/order")
@RestController
@Api(tags = "订单相关接口")
public class OrderController {

    @Autowired
     private OrderService orderService;
    /**
     * 通过ID查询订单
     * @return
     */
    @ApiOperation("通过ID查询订单")
    @GetMapping("/details/{id}")
    public Result<Orders> FindById(@PathVariable Integer id){

        Orders orders = orderService.FindById(id);

        return Result.success(orders);
    }

    /**
     * 通过各种条件分页查询order表
     * @return
     */
    @ApiOperation("通过各种条件分页查询order表")
    @GetMapping("/conditionSearch")
    public Result<PageResult> FindOrder(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = orderService.FindOrder(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 各个状态的订单数量统计
     */
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> GetStatistics(){

        OrderStatisticsVO orderStatisticsVO = orderService.GetStatistics();

        return Result.success(orderStatisticsVO);
    }

    /**
     * 完成订单
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result CompleteById(@PathVariable Integer id){
        orderService.CompleteById(id);
        return Result.success();
    }

    /**
     * 取消订单
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result Cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderService.Cancel(ordersCancelDTO);
        return Result.success();
    }
    /**
     * 拒绝订单
     */
    @PutMapping("/rejection")
    @ApiOperation("拒绝订单")
    public Result Rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        orderService.Rejection(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 派送订单
     */
    @PutMapping("delivery/{id}")
    @ApiOperation("派送订单")
    public Result Delivery(@PathVariable Integer id){
        orderService.delivery(id);
        return Result.success();
    }
    /**
     * 接单
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result Confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){

        orderService.Confirm(ordersConfirmDTO);
        return Result.success();
    }
}
